<template>
  <d2-container>
    <template slot="header">
        <template>
            <el-form
                :inline="true"
                size="mini"
                style="margin-bottom: -18px;">
                <el-form-item>
                  <el-button
                      type="primary"
                      @click="handleEdit('insert')">
                      <d2-icon name="plus"/>
                      新增
                  </el-button>
                </el-form-item>

                <el-form-item>
                  <el-button
                      type="danger"
                      @click="">
                      <d2-icon name="trash-o"/>
                      刪除
                  </el-button>
                </el-form-item>
                
            </el-form>
        </template>
    </template>
    
    <template>
        <el-table 
        :data="tableData" 
        style="width: 100%">
        <el-table-column type="selection" width="50" align="center" />
            <el-table-column label="ID" width="80" prop="id"/>
            <el-table-column label="名称" width="200" prop="name"/>
            <el-table-column label="描述" width="400" prop="description"/>
            <el-table-column label="创建时间" width="300">
                <template slot-scope="scope">
                    <i class="el-icon-time"></i>
                    <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
                </template>
            </el-table-column>
            <el-table-column label="修改时间" width="300">
                <template slot-scope="scope">
                    <i class="el-icon-time"></i>
                    <span style="margin-left: 10px">{{ scope.row.updateTime }}</span>
                </template>
            </el-table-column>

            <el-table-column label="操作" align="center" width="150">
                <template slot-scope="scope">
                    <el-button type="primary" title="编辑" size="mini" icon="el-icon-edit" circle @click="handleEdit(scope.row,'update')"></el-button>
                    <el-button type="danger" title="删除" size="mini" icon="el-icon-delete" circle :loading="scope.row.delLoading" @click="handleDelete('delOne',[scope.row])"></el-button>
                </template>
            </el-table-column>

        </el-table>

        <page-footer
            slot="footer"
            :current="page.current"
            :loading="loading"
            :size="page.size"
            :total="page.total"
            @change="tableLoad({},false)"/>

    </template>

    <!-- 表单弹窗 -->
    <!-- :org_id="org_id"
                :org_name="org_name"
                :treeData="treeData" -->
        <data-form
                @tableLoad="tableLoad"
                ref="dataForm">
        </data-form>
  </d2-container>
</template>

<script>
import dataForm from './dataForm'
import {httpGet,httpPost} from '@/api/sys/http';
import PageFooter from '@/components/footer'

export default {
  title: 'tag',
  index: 14,
  components:{
      dataForm,
      PageFooter
  },
  data() {
    return {
        loading:false,
        delLoading:false,
        tableData: [],
        cascade:true,
        page: {
            current: 1,
            size: 0,
            total: 0
        },
    }
  },
  mounted() {
        this.$nextTick(() => {
            let self = this;
            self.tableLoad({},true);
        })
    },
  methods: {
      tableLoad(params,jumpFirst){
            var self = this;
            // if(jumpFirst) self.$refs.pagination.current = 1;
 
            params = {
                pageNumber: self.page.current,
                pageSize: self.page.size
            };
            self.loading = true;
            httpPost('/tag/list', params).then(res => {
                self.loading = false;
                self.tableData = res.rows
                self.page.total = res.total;
            });
        },


    handleEdit: function (row,method) {
        // if(!this.org_id){
        //     this.org_id = this.treeData[0].id;
        //     this.org_name = this.treeData[0].org_name;
        // }
        this.$refs.dataForm.open(row,method);
    },
    handleDelete (index, row) {
      console.log(index, row)
    },
    handleStatusChange(){

    }
  }
}
</script>

